﻿var app = angular.module('LoginPage', []);


app.controller('LoginController', function ($scope, $http, $window, $compile, $filter) {
    $scope.IsCheck = false;

    $scope.UserLogin = function (user, psd, type) {
        if (user == null || user == "") {
            alertify.alert("请输入工号");
            return false;
        }
        if (psd == null || psd == "") {
            alertify.alert("请输入密码");
            return false;
        }
        $http({
            method: 'POST',
            url: '../Account/CheckLogin',
            data: { 'userName': user, 'password': psd, 'type': type }
        })
            .success(function (ret) {
                if (ret.Code == 200) {
                    $http({
                        method: 'POST',
                        url: '../Account/CreateMyTask'
                    })
                    window.location = '../SafetyResponsibility/MyResponsibility';
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {

            });
    }

    $scope.ShowMyAccount = function () {
        $http({
            method: 'POST',
            url: '../Account/GetUserAccount',
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.MyInfo = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {

            });
    }

    $scope.Test = function () {
        $http.get('http://192.168.0.110:8050/Account/TestOrg').success(function (data) {

            console.log(data);
            
        });

        //var myUrl = "http://192.168.0.110:8050/Account/TestOrg?callback=JSON_CALLBACK";
        //$http.jsonp(myUrl).success(function (response) {
        //    console.log(response);
        //});
        //$http({
        //    method: 'GET',
        //    url: 'http://192.168.0.110:8050/Account/TestOrg',
        //})
        //    .success(function (ret) {
        //        common.success($scope, null, ret);
        //        if (ret.Code == 100) {
        //            $scope.MyInfo = ret.Data;
        //        }
        //        else {
        //            alertify.alert(ret.Msg);
        //        }
        //    })
        //    .error(function (data, status, headers, config) {

        //    });
    }

    $scope.GetMessagePageList = function (model, page) {
        $scope.DataLoading = true;
        $scope.MyMessageList = [];
        $http({
            method: 'POST',
            url: '../Account/GetHiddenTroublePageList',
            data: { "SearchText": model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.MyMessageList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.ShowTip = function (text) {
        alertify.alert(text);
    }
});


